package edu.ahut.corejava2;

import java.util.Arrays;
import java.util.Comparator;

class MyComparator implements Comparator<String> {

    public int compare(String s1, String s2) {
        return s1.length() - s2.length();
    }

}

public class UnnamedClassDemo {
    public static void main(String[] args) {
        String[] words = "To know everything is to know nothing".split("\\s+");
        System.out.println(Arrays.toString(words));
        Arrays.sort(words);//按照字典序 升序
        System.out.println(Arrays.toString(words));

        MyComparator comp = new MyComparator();
        Arrays.sort(words, comp);//按照长度从小到大
        System.out.println(Arrays.toString(words));


        Arrays.sort(words, new MyComparator());//按照长度从小到大
        System.out.println(Arrays.toString(words));


        Arrays.sort(words, new Comparator<String>() {

            public int compare(String s1, String s2) {
                return s2.length() - s1.length();
            }
        });//按照长度从大到小排，
        System.out.println(Arrays.toString(words));

    }


}
